var TILES = [];

// Tiles of map
loadTile('summertiles');
log(TILES);

var TILE_OBJ = 2;

function loading(){
	TILE_OBJ --;
	if(TILE_OBJ == 0)
		run();
}

function loadTile(src){
	var tile = new Image();
	tile.src = 'assets/tiles/' + src + '.gif';
	// log(tile.src);

	TILES[src] = tile;

	tile.onload = loading;
}

function renderTiles(obj){
	var o = obj;
	// log('renderTiles');

	for (var x = 0; x < o.grid.length; x++) {
		for (var y = 0; y < o.grid[x].length; y++) {
			var tile = o.grid[x][y];
			// log(tile);
			// log(tile);
			// log('ctx.drawImage('+TILES[tile.name]+','+tile.bgx+','+tile.bgy+','+tile.bgw+','+tile.bgh+',0,0,'+tile.bgw+','+tile.bgh+');');
			ctx.drawImage(TILES[tile.name],
				tile.bgx, // position x en image source
				tile.bgy, // position y en image source
				tile.bgw, // largeur image source
				tile.bgh, // hauteur image source
				x*32, // position X sur canvas (pos X + offset X)
				y*32, // position Y sur canvas (pos Y + offset Y)
				tile.bgw, // largeur sur canvas de destination
				tile.bgh  // hauteur sur canvas de destination
			);
		}
	}	
}